#!/usr/bin/perl -w
use DBI;
use mydb;
use function;

sub set_videoinfo {

        $rowid = shift||"";
        $file = shift||"";

        unless (open FH, "-|") {

                exec "ffmpeg -y -i $file 2>&1|tr '\r' '\n'";        # 用exec执行另一个程序
                exit;
        }
        while (<FH>) {

          $s_tt = $_;
          $index_duration = index($s_tt, "Duration");

          if($index_duration >= 0) {

            @a_all = split(/,/, $s_tt);
            @a_a0 = split(/:/, $a_all[0]);
#convert String Date to second;

	    $playtime = $a_a0[1]*3600 + $a_a0[2]*60 + $a_a0[3];
            update_task_field($rowid, "playtime", $playtime);

            @a_a1 = split(/:/, $a_all[2]);
            $s_bitrate = $a_a1[1];
            update_task_field($rowid, "bitrate", $s_bitrate);
        }

         $index_Video = index($s_tt, "Video");
         if($index_Video >= 0) {

            $s_tmp = substr($s_tt, $index_Video+6);
            $s_tmp =~ s/^\s+//;
            update_task_field($rowid, "vcode", $s_tmp);
            @a_video = split(/,/, $s_tmp);
            $s_resolution = get_val($a_video[2]);
            update_task_field($rowid, "resolution", $s_resolution);
#           $s_bitrate =  get_val($a_video[3]);
#           update_task_field($rowid, "bitrate", $s_bitrate);
            $s_fps = get_val($a_video[4]);
            update_task_field($rowid, "fps", $s_fps);
        }

        $index_Audio = index($s_tt, "Audio");
        if($index_Audio >= 0) {

            $s_tmp = substr($s_tt, $index_Audio+6);
            $s_tmp =~ s/^\s+//;
            update_task_field($rowid, "acode", $s_tmp);
        }
    }
}
1;
